package com.ludomancy.sos64.components;

import java.awt.Graphics;
import java.awt.Point;
import java.util.Vector;

import com.ludomancy.gamelib.ImageAnimation;
import com.ludomancy.gamelib.ImageStrip;
import com.ludomancy.gamelib.Randomizer;
import com.ludomancy.gamelib.ResourceManager;
import com.ludomancy.sos64.Accumulator;
import com.ludomancy.sos64.Component;
import com.ludomancy.sos64.Game;

public class Teen64 extends Component
{
	private ImageAnimation grown;
	private Accumulator stir;
	
	public Teen64(Point pos)
	{
		super(pos.x,pos.y);
		if(grown == null)
		{
			grown = new ImageAnimation(new ImageStrip(ResourceManager.getImage("grown.png"), 47, 27), 8);
		}
		stir = new Accumulator(Randomizer.getRandom(800,3000));
//		grown.looping = true;
	}
	
	public Point getSize()
	{
		return new Point(47,27);
	}
	
	public boolean isOrganic()
	{
		return true;
	}

	public void paint(Graphics g, int px, int py)
	{
		grown.paintCurrentFrame(g, px, py);
	}
	
	public void update()
	{
		stir.update();
		grown.update();
		if(stir.isDone())
		{
			grown.rewind();
			grown.play();
			stir.reset(Randomizer.getRandom(800,3000));
		}
		Dam b = null;
		Vector v = Game.game.getComponents(Dam.class);
		if(!v.isEmpty())
		{
			b = (Dam) v.elementAt(0);
		}
		if(b != null && b.area().contains(getHotspot()))
		{
			b.consume();
			if(grown.isOver())
				grown.rewind();
			grown.play();
		}
	}
}
